﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using Indeco.G24.Web.UI;
using Indeco.G24.Entities;
using Indeco.G24.Services;
using DevExpress.Web.ASPxNavBar;
using DevExpress.Web.ASPxGridView;

namespace Indeco.G24.Website.Price.Admin
{
    public partial class PriceList : Indeco.G24.Web.G24Page
    {
        /// <summary>
        /// nhaCungCap
        /// </summary>
        public NhaCungCap nhaCungCap = new NhaCungCap();
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

            try
            {
                if (Session["IDNguoiDung"].ToString() == Guid.Empty.ToString())
                {
                    Response.Redirect("~/Login.aspx?ReturnUrl=" + Server.UrlEncode(Request.RawUrl));
                }
                else
                {
                    NguoiDungNhaCungCapService nguoiDungNhaCungCapService = new NguoiDungNhaCungCapService();
                    TList<NguoiDungNhaCungCap> listNN = nguoiDungNhaCungCapService.GetByIDNguoiDung(new Guid(Session["IDNguoiDung"].ToString()));
                    Session["IDNhaCungCap"] = listNN[0].IDNhaCungCap;
                }
            }
            catch
            {
                Response.Redirect("~/Login.aspx?ReturnUrl=" + Server.UrlEncode(Request.RawUrl));
            }
            lblError.Text = "";
            if (!IsPostBack)
            {
                thoiDiemHetHieuLuc.Date = DateTime.Now;
                try
                {
                    BindData();
                    generalSiteMap();
                }
                catch { }
            }
            BindToGrid();
            if (!IsPostBack && !IsCallback)
            {
                ApplyLayout(0);
            }
            //CSSLink = "~/PopupControl/CSS/ModalWindow.css"; // Register css file

        }
        private void BindToGrid()
        {
            NhaCungCapDiaBanService nhaCungCapDiaBanService = new NhaCungCapDiaBanService();
            TList<NhaCungCapDiaBan> listNhaCungCapDiaBan = nhaCungCapDiaBanService.GetByIDNhaCungCap(new Guid(Session["IDNhaCungCap"].ToString()));
            nhaCungCapDiaBanService.DeepLoad(listNhaCungCapDiaBan);
            foreach (NhaCungCapDiaBan nhaCungCapDiaBan in listNhaCungCapDiaBan)
            {
                Control UserControlGridBangGiaSanPham = this.LoadControl("~/Price/Admin/UserControls/frmGridBangGiaSanPham.ascx");
                UserControls.frmGridBangGiaSanPham frmGridBangGiaSanPham = (UserControls.frmGridBangGiaSanPham)UserControlGridBangGiaSanPham;
                frmGridBangGiaSanPham.ID_DiaBan = nhaCungCapDiaBan.IDDiaBan.ToString();
                frmGridBangGiaSanPham.ID_NhaCungCap = Session["IDNhaCungCap"].ToString();
                frmGridBangGiaSanPham.TenDiaBan = "<font color=\"red\">" + nhaCungCapDiaBan.IDDiaBanSource.Ten + "</font>";
                PanelBangGiaSanPham.Controls.Add(frmGridBangGiaSanPham);
            }
        }
        protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            int layoutIndex = -1;
            if (int.TryParse(e.Parameters, out layoutIndex))
                ApplyLayout(layoutIndex);
        }
        void ApplyLayout(int layoutIndex)
        {
            BangGiaSanPham.BeginUpdate();
            try
            {
                BangGiaSanPham.ClearSort();
                switch (layoutIndex)
                {
                    case 0:
                        BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[0]);
                        BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[1]);
                        break;
                    case 1:
                        BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[2]);
                        break;
                    case 2:
                        BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[3]);
                        break;
                }
            }
            finally
            {
                BangGiaSanPham.EndUpdate();
            }
            BangGiaSanPham.ExpandAll();
        }
        protected void btnXlsExport_Click(object sender, EventArgs e)
        {
            this.gridExport.WriteXlsToResponse();
        }
        protected void btnRtfExport_Click(object sender, EventArgs e)
        {
            this.gridExport.WriteRtfToResponse();
        }

        //Tao bang gia
        /// <summary>
        /// Ham BindData()
        /// </summary>
        private void BindData()
        {
            //Bind Danh muc thuc thi vao CheckBoxList addlistSanPhamDanhMuc va addlistSanPhamDanhMuc2
            SanPhamDanhMucService sanPhamDanhMucService = new SanPhamDanhMucService();
            int totalCount = -1;
            TList<SanPhamDanhMuc> lstSPDM = sanPhamDanhMucService.GetPaged("ID_SanPhamDanhMuc NOT IN (select distinct ID_SanPhamDanhMucCha from tb_SanPhamDanhMuc )","Ten",0,100000,out totalCount);
            addlistSanPhamDanhMuc.DataSource = lstSPDM;
            addlistSanPhamDanhMuc.DataBind();
            //foreach (SanPhamDanhMuc sanPhamDanhMuc in lstSPDM)
            //{
            //    ListItem item = new ListItem();
            //    item.Value = sanPhamDanhMuc.IDSanPhamDanhMuc.ToString();
            //    item.Text = sanPhamDanhMuc.Ten;
            //    addlistSanPhamDanhMuc.Items.Add(item);
            //    addlistSanPhamDanhMuc2.Items.Add(item);
            //}
            //Bind Dia ban vao DropDownList listDiaBan 
            //Bind Dia ban cua nha cung cap vao CheckBoxList listDiaBanDangSuDung
            DiaBanService diaBanService = new DiaBanService();
            TList<DiaBan> lstDiaBan = diaBanService.GetByIDNhaCungCapFromNhaCungCapDiaBan(new Guid(Session["IDNhaCungCap"].ToString()));
            foreach (DiaBan diaBan in lstDiaBan)
            {
                ListItem item = new ListItem();
                item.Value = diaBan.IDDiaBan.ToString();
                item.Text = diaBan.Ten;
                listDiaBanDangSuDung.Items.Add(item);
                listDiaBan.Items.Add(item);
            }
            listDiaBanDangSuDung.ClearSelection();
            //Bind Dia ban vao DropDownList addListDiaBan
            lstDiaBan.Clear();
            lstDiaBan = diaBanService.GetAll();
            foreach (DiaBan diaBan in lstDiaBan)
            {
                ListItem item = new ListItem();
                item.Value = diaBan.IDDiaBan.ToString();
                item.Text = diaBan.Ten;
                addListDiaBan.Items.Add(item);
            }
            //Bind Ngoai Te vao DropDownList listNgoaite
            NgoaiTeService ngoaiTeService = new NgoaiTeService();
            TList<NgoaiTe> lstNgoaiTe = ngoaiTeService.Find("TrangThai = True");
            foreach (NgoaiTe ngoaiTe in lstNgoaiTe)
            {
                ListItem item = new ListItem();
                item.Value = ngoaiTe.IDNgoaiTe.ToString();
                item.Text = ngoaiTe.KyHieu;
                if (ngoaiTe.MacDinh == true)
                    item.Selected = true;
                listNgoaite.Items.Add(item);
            }
            getListDanhMuc();
        }
        /// <summary>
        /// Ham getListDanhMuc()
        /// </summary>
        private void getListDanhMuc()
        {
            NhaCungCapSanPhamDanhMucService nhaCungCapSanPhamDanhMucService = new NhaCungCapSanPhamDanhMucService();
            TList<NhaCungCapSanPhamDanhMuc> nhaCungCapSanPhamDanhMuc = nhaCungCapSanPhamDanhMucService.Find("ID_DiaBan = '" + listDiaBan.SelectedValue + "' AND ID_NhaCungCap = '" + Session["IDNhaCungCap"].ToString() + "'");
            TList<SanPhamDanhMuc> lstSanPhamDanhMuc = new TList<SanPhamDanhMuc>();
            SanPhamDanhMucService sanPhamDanhMucService = new SanPhamDanhMucService();
            foreach (NhaCungCapSanPhamDanhMuc ncc in nhaCungCapSanPhamDanhMuc)
            {
                lstSanPhamDanhMuc.Add(sanPhamDanhMucService.GetByIDSanPhamDanhMuc(ncc.IDSanPhamDanhMuc));
            }
            listSanPhamDanhMuc.DataSource = lstSanPhamDanhMuc;
            listSanPhamDanhMuc.DataBind();
            listDanhMucSanPhamDaChon.DataSource = lstSanPhamDanhMuc;
            listDanhMucSanPhamDaChon.DataBind();
            //Bind Danh muc thuc thi vao CheckBoxList addlistSanPhamDanhMuc2
            int totalCount = -1;
            TList<SanPhamDanhMuc> lstSPDM = sanPhamDanhMucService.GetPaged("ID_SanPhamDanhMuc NOT IN (select distinct ID_SanPhamDanhMucCha from tb_SanPhamDanhMuc )", "Ten", 0, 100000, out totalCount);
            foreach (SanPhamDanhMuc sanPhamDanhMuc in lstSanPhamDanhMuc)
            {
                lstSPDM.Remove(sanPhamDanhMuc);
            }
            addlistSanPhamDanhMuc2.DataSource = lstSPDM;
            addlistSanPhamDanhMuc2.DataBind();
            panelDanhMucDangCungCap.GroupingText = "Tỉnh / Thành phố: <b><font color=red>" + listDiaBan.SelectedItem.Text + "</font></b>";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void listDiaBan_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                getListDanhMuc();
            }
            catch
            { }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnTaomoibanggia_Click(object sender, EventArgs e)
        {
            try
            {
                SanPham sanPham = new SanPham();
                SanPhamService sanPhamService = new SanPhamService();
                BangGiaSanPham bangGiaSanPham = new BangGiaSanPham();
                BangGiaSanPhamService bangGiaSanPhamService = new BangGiaSanPhamService();
                NhaCungCap nhaCungCap = new NhaCungCap();
                NhaCungCapService nhaCungCapService = new NhaCungCapService();
                sanPham.IDSanPham = Guid.NewGuid();
                sanPham.IDSanPhamDanhMuc = new Guid(listSanPhamDanhMuc.SelectedValue);
                nhaCungCap = nhaCungCapService.GetByIDNhaCungCap(new Guid(Session["IDNhaCungCap"].ToString()));
                sanPham.NhaCungCap = nhaCungCap.NhaCungCap;
                sanPham.Ten = txtTenSanPham.Text.Trim();
                sanPham.MoTa = txtThongTinThem.Html;
                sanPham.NhaSanXuat = txtNhaSanXuat.Text.Trim();
                if (txtDonViTinh.Text.Trim() == "")
                    sanPham.DonViTinh = "-";
                else
                    sanPham.DonViTinh = txtDonViTinh.Text.Trim();
                sanPham.TrangThai = true;
                sanPham.ViTri = 0;
                sanPham.SoLanXem = 0;
                sanPham.ThoiDiemChinhSua = DateTime.Now;
                sanPham.ThoiDiemCapNhat = DateTime.Now;
                if (!sanPhamService.Insert(sanPham))
                    lblError.Text = "Không cập nhật được sản phẩm này<br />";
                else
                {
                    bangGiaSanPham.IDSanPham = sanPham.IDSanPham;
                    bangGiaSanPham.IDNhaCungCap = nhaCungCap.IDNhaCungCap;
                    bangGiaSanPham.IDDiaBan = new Guid(listDiaBan.SelectedValue);
                    bangGiaSanPham.KichHoat = true;
                    bangGiaSanPham.ChungThuc = true;
                    bangGiaSanPham.TrangThai = true;
                    bangGiaSanPham.ChoNhapGia = false;
                    if (txtGiasanpham.Text.Trim() == "")
                    {
                        bangGiaSanPham.DonGia = 0;
                    }
                    else
                    {
                        try
                        {
                            bangGiaSanPham.DonGia = Convert.ToDecimal(txtGiasanpham.Text.Trim());
                        }
                        catch
                        {
                            bangGiaSanPham.DonGia = 0;
                        }
                    }
                    bangGiaSanPham.VAT = Convert.ToDouble(listVAT.SelectedValue);
                    bangGiaSanPham.IDNgoaiTe = new Guid(listNgoaite.SelectedValue);
                    bangGiaSanPham.SoLuongTrongKho = -1;
                    bangGiaSanPham.TieuChuanKyThuat = txtTCKT.Text.Trim();
                    bangGiaSanPham.Thongtinthem = txtChinhSachBanHang.Html;
                    bangGiaSanPham.ThoiDiemDangBaoGia = DateTime.Now;
                    bangGiaSanPham.ThoiDiemHetHieuLuc = DateTime.Now;
                    bangGiaSanPham.ThoiDiemChinhSua = DateTime.Now;
                    bangGiaSanPham.ThoiDiemCapNhat = DateTime.Now;
                    bangGiaSanPham.KeyBangGia = Guid.NewGuid();
                    if (!bangGiaSanPhamService.Insert(bangGiaSanPham))
                        lblError.Text += "Không cập nhật được bảng giá sản phẩm <font color=red>" + sanPham.Ten + "</font><br />";
                }
                generalSiteMap();
            }
            catch
            {
                lblError.Text = "Không thêm mới được sản phẩm này<br />";
            }
            txtTenSanPham.Text = "";
            txtGiasanpham.Text = "";
            txtThongTinThem.Html = "";
            //Server.Transfer(Request.RawUrl);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRemoveDiaBan_Click(object sender, EventArgs e)
        {
            foreach (ListItem item in listDiaBanDangSuDung.Items)
            {
                if (item.Selected)
                {
                    NhaCungCapDiaBanService nhaCungCapDiaBanService = new NhaCungCapDiaBanService();
                    if (!nhaCungCapDiaBanService.Delete(new Guid(item.Value), new Guid(Session["IDNhaCungCap"].ToString())))
                        lblError.Text += "Chưa xóa được NhaCungCapDiaBan<br>";
                    NhaCungCapSanPhamDanhMucService nhaCungCapSanPhamDanhMucService = new NhaCungCapSanPhamDanhMucService();
                    TList<NhaCungCapSanPhamDanhMuc> nhaCungCapSanPhamDanhMuc = nhaCungCapSanPhamDanhMucService.Find("ID_DiaBan = '" + item.Value + "' AND ID_NhaCungCap = '" + Session["IDNhaCungCap"].ToString() + "'");
                    nhaCungCapSanPhamDanhMucService.Delete(nhaCungCapSanPhamDanhMuc);
                    BangGiaSanPhamService bangGiaSanPhamService = new BangGiaSanPhamService();
                    TList<BangGiaSanPham> listBangGiaSanPham = bangGiaSanPhamService.Find("ID_DiaBan = '" + item.Value + "' AND ID_NhaCungCap = '" + Session["IDNhaCungCap"].ToString() + "'");
                    bangGiaSanPhamService.Delete(listBangGiaSanPham);
                }
            }
            Server.Transfer(Request.RawUrl);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnThemMoiDiaBan_Click(object sender, EventArgs e)
        {
            NhaCungCapDiaBan nhaCungCapDiaBan = new NhaCungCapDiaBan();
            nhaCungCapDiaBan.IDDiaBan = new Guid(addListDiaBan.SelectedValue);
            nhaCungCapDiaBan.IDNhaCungCap = new Guid(Session["IDNhaCungCap"].ToString());
            nhaCungCapDiaBan.ViTri = 1;
            nhaCungCapDiaBan.TrangThai = true;
            NhaCungCapDiaBanService nhaCungCapDiaBanService = new NhaCungCapDiaBanService();
            if (!nhaCungCapDiaBanService.Insert(nhaCungCapDiaBan))
                lblError.Text = "Địa bàn chưa cập nhật<br>";
            NhaCungCapSanPhamDanhMuc nhaCungCapSanPhamDanhMuc = new NhaCungCapSanPhamDanhMuc();
            int i = 1;
            foreach (ListItem item in addlistSanPhamDanhMuc.Items)
            {
                if (item.Selected)
                {
                    nhaCungCapSanPhamDanhMuc.IDSanPhamDanhMuc = new Guid(item.Value);
                    nhaCungCapSanPhamDanhMuc.IDDiaBan = new Guid(addListDiaBan.SelectedValue);
                    nhaCungCapSanPhamDanhMuc.IDNhaCungCap = new Guid(Session["IDNhaCungCap"].ToString());
                    nhaCungCapSanPhamDanhMuc.ViTri = i;
                    nhaCungCapSanPhamDanhMuc.TrangThai = true;
                    nhaCungCapSanPhamDanhMuc.HienThi = true;
                    nhaCungCapSanPhamDanhMuc.ThoiDiemCapNhat = DateTime.Now;
                    nhaCungCapSanPhamDanhMuc.ThoiDiemChinhSua = DateTime.Now;
                    NhaCungCapSanPhamDanhMucService nhaCungCapSanPhamDanhMucService = new NhaCungCapSanPhamDanhMucService();
                    if (!nhaCungCapSanPhamDanhMucService.Insert(nhaCungCapSanPhamDanhMuc))
                        lblError.Text += "Danh mục sản phẩm <b>" + item.Text + "</b> chưa cập nhật<br>";
                    else
                        i = i + 1;
                }
            }
            Server.Transfer(Request.RawUrl);
        }

        protected void btnThemMoiSanPhamDanhMuc_Click(object sender, EventArgs e)
        {
            NhaCungCapSanPhamDanhMuc nhaCungCapSanPhamDanhMuc = new NhaCungCapSanPhamDanhMuc();
            int i = 1;
            foreach (ListItem item in addlistSanPhamDanhMuc2.Items)
            {
                if (item.Selected)
                {
                    nhaCungCapSanPhamDanhMuc.IDSanPhamDanhMuc = new Guid(item.Value);
                    nhaCungCapSanPhamDanhMuc.IDDiaBan = new Guid(listDiaBan.SelectedValue);
                    nhaCungCapSanPhamDanhMuc.IDNhaCungCap = new Guid(Session["IDNhaCungCap"].ToString());
                    nhaCungCapSanPhamDanhMuc.ViTri = i;
                    nhaCungCapSanPhamDanhMuc.TrangThai = true;
                    nhaCungCapSanPhamDanhMuc.HienThi = true;
                    nhaCungCapSanPhamDanhMuc.ThoiDiemCapNhat = DateTime.Now;
                    nhaCungCapSanPhamDanhMuc.ThoiDiemChinhSua = DateTime.Now;
                    NhaCungCapSanPhamDanhMucService nhaCungCapSanPhamDanhMucService = new NhaCungCapSanPhamDanhMucService();
                    if (!nhaCungCapSanPhamDanhMucService.Insert(nhaCungCapSanPhamDanhMuc))
                        lblError.Text += "Danh mục sản phẩm <b>" + item.Text + "</b> chưa cập nhật<br>";
                    else
                        i = i + 1;
                }
            }
            Server.Transfer(Request.RawUrl);
        }

        protected void btnRemoveSanPhamDanhMuc_Click(object sender, EventArgs e)
        {
            NhaCungCapSanPhamDanhMucService nhaCungCapSanPhamDanhMucService = new NhaCungCapSanPhamDanhMucService();
            BangGiaSanPhamService bangGiaSanPhamService = new BangGiaSanPhamService();
            SanPhamService sanPhamService=new SanPhamService();
            NhaCungCapService nhaCungCapService=new NhaCungCapService();
            NhaCungCap nhaCungCap = nhaCungCapService.GetByIDNhaCungCap(new Guid(Session["IDNhaCungCap"].ToString()));
            TList<BangGiaSanPham> listBangGiaSanPham=new TList<BangGiaSanPham>();
            foreach (ListItem item in listDanhMucSanPhamDaChon.Items)
            {
                if (item.Selected)
                {
                    if (nhaCungCapSanPhamDanhMucService.Delete(new Guid(listDiaBan.SelectedValue), new Guid(Session["IDNhaCungCap"].ToString()), new Guid(item.Value)))
                    {
                        TList<SanPham> listSanPham = sanPhamService.Find("ID_SanPhamDanhMuc = '" + item.Value + "' AND NhaCungCap = '" + nhaCungCap.NhaCungCap + "'");
                        foreach (SanPham sanPham in listSanPham)
                        {
                            listBangGiaSanPham = bangGiaSanPhamService.Find("ID_DiaBan = '" + listDiaBan.SelectedValue + "' AND ID_NhaCungCap = '" + Session["IDNhaCungCap"].ToString() + "' AND ID_SanPham = '" + sanPham.IDSanPham.ToString() + "'");
                            foreach (BangGiaSanPham bangGiaSanPham in listBangGiaSanPham)
                            {
                                if (!bangGiaSanPhamService.Delete(bangGiaSanPham))
                                    lblError.Text += "Không xóa được BangGiaSanPham<br>";
                            }
                        }
                    }
                    else
                    {
                        lblError.Text += "Không xóa được NhaCungCapSanPhamDanhMuc<br>";
                    }
                }
            }
            Server.Transfer(Request.RawUrl);
        }


        //Tao siteMap
        private string _siteMapFileName = "SiteMap/ProvinceActive.sitemap";
        private const String SiteMapNodeName = "siteMapNode";        
        public void generalSiteMap()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + _siteMapFileName;
            XmlDocument siteMapXml = new XmlDocument();
            siteMapXml.Load(AppDomain.CurrentDomain.BaseDirectory + _siteMapFileName);
            XmlElement rootElement = (XmlElement)siteMapXml.GetElementsByTagName(SiteMapNodeName)[0];
            rootElement.RemoveAll();
            rootElement.SetAttribute("url", "~/Price/Default.aspx");
            rootElement.SetAttribute("title", "Bảng giá");
            rootElement.SetAttribute("description", "");
            siteMapXml.Save(path);
            addNode(rootElement);
            siteMapXml.Save(path);
        }
        private void addNode(XmlElement rootElement)
        {
            DiaBanService diaBanService = new DiaBanService();
            NhaCungCapService nhaCungCapService = new NhaCungCapService();
            int totalCount = -1;
            TList<DiaBan> listDiaBan = diaBanService.GetPaged("ID_DiaBan in (SELECT distinct ID_DiaBan FROM tb_BangGiaSanPham)", "", 0, 100000, out totalCount);
            foreach (DiaBan diaBan in listDiaBan)
            {
                XmlElement diaBanNode = AddDynamicChildElement(rootElement, "~/Price/Default.aspx?IDDiaBan=" + diaBan.IDDiaBan.ToString(), diaBan.Ten, "");
                TList<NhaCungCap> listNhaCungCap = nhaCungCapService.GetPaged("ID_NhaCungCap in (select distinct ID_NhaCungCap FROM tb_BangGiaSanPham where ID_DiaBan='" + diaBan.IDDiaBan.ToString() + "')", "", 0, 100000, out totalCount);
                foreach (NhaCungCap nhaCungCap in listNhaCungCap)
                {
                    XmlElement nhaCungCapNode = AddDynamicChildElement(diaBanNode, "~/Provider/Default.aspx?IDNhaCungCap=" + nhaCungCap.IDNhaCungCap.ToString() + "#" + diaBan.IDDiaBan.ToString(), nhaCungCap.Ten, "");
                }
            }


            // TList<BangGiaSanPham> danhmuccha = DataRepository.TinTucDanhMucProvider.Find("id_tintucdanhmuccha='" + Guid.Empty.ToString() + "'");
            //if (danhmuccha.Count > 0)
            //{
            //    foreach (TinTucDanhMuc dm in danhmuccha)
            //    {
            //        XmlElement teams = AddDynamicChildElement(rootElement, "~/News/Category.aspx?IDTinTucDanhMuc=" + dm.IDTinTucDanhMuc.ToString(), dm.Ten, "");
            //        TList<TinTucDanhMuc> danhmucon = DataRepository.TinTucDanhMucProvider.Find("id_tintucdanhmuccha='" + dm.IDTinTucDanhMuc + "'");
            //        if (danhmucon.Count > 0)
            //        {
            //            foreach (TinTucDanhMuc dmc in danhmucon)
            //            {
            //                AddDynamicChildElement(teams, "~/News/Category.aspx?IDTinTucDanhMuc=" + dmc.IDTinTucDanhMuc.ToString(), dmc.Ten, "");
            //            }
            //        }
            //    }

            //}
        }
        private static XmlElement AddDynamicChildElement(XmlElement parentElement, String url, String title, String description)
        {
            // Create new element from the parameters
            XmlElement childElement = parentElement.OwnerDocument.CreateElement(SiteMapNodeName);
            childElement.SetAttribute("url", url);
            childElement.SetAttribute("title", title);
            childElement.SetAttribute("description", description);
            // Add it to the parent
            parentElement.AppendChild(childElement);
            return childElement;
        }

    }
}
